import 'package:basic_common/app_theme.dart';
import 'package:basic_common/common_exports.dart';
import 'package:basic_widgets/app_bar_widget.dart';
import 'package:basic_widgets/text_widget.dart';
import 'model/my_presc_list_data.dart';
import 'mypresclist_controller.dart';

class MyPrescListPage extends GetView<MyPrescListController> {
  const MyPrescListPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: backAppbar(title: "我的处方"),
      body: SingleChildScrollView(
        physics: AlwaysScrollableScrollPhysics(),
        child: Column(
          children: [buldListView()],
        ),
      ),
    );
  }

  Widget buldListView() {
    return SizedBox(
      child: GetBuilder<MyPrescListController>(
        id: 'prescList',
        builder: (controller) => ListView.builder(
          physics: const NeverScrollableScrollPhysics(),
          shrinkWrap: true,
          itemBuilder: (context, index) {
            MyPrescListData itemData = controller.presclistData[index];
            return GestureDetector(
                onTap: () => Get.toNamed(AppRoutes.myprescdetail,
                    arguments: {"prescId": itemData.id.toString()!}),
                child: buildListItem(index, itemData));
          },
          itemCount: controller.presclistData.length,
        ),
      ),
    );
  }

  /// listViewItem
  Widget buildListItem(int index, MyPrescListData itemData) {
    return Card(
      elevation: 0,
      child: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Row(
                  children: [
                    norTitle(title: "Rp", isBlod: true),
                    SizedBox(
                      width: ScreenHelper.width(15),
                    ),
                    Text(
                      "${controller.showText(index)}",
                      textAlign: TextAlign.left,
                      style: TextStyle(color: AppTheme.dartWeakTextColor),
                    ),
                  ],
                ),
                Text(
                  "共${itemData.drugs!.length}种药品",
                  textAlign: TextAlign.end,
                  style: TextStyle(fontWeight: FontWeight.normal,fontSize: ScreenHelper.sp(14)),
                ),
              ],
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text(
                  "临床诊断：${itemData.diagnosis!}",
                  style: TextStyle(
                      color: AppTheme.redtextColor,
                      fontSize: ScreenHelper.sp(15)),
                ),
                Image.asset(
                  "assets/profile/icon_arrow_next.png",
                  width: ScreenHelper.width(18),
                  package: "basic_common",
                )
              ],
            ),
            Text(
              "${itemData.drugs![0].drugName!} x1盒",
              style: TextStyle(
                  color: AppTheme.dartTextColor, fontSize: ScreenHelper.sp(15)),
            ),
          ],
        ),
      ),
    );
  }
}
